<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function Dog({ name, type, age }) {
      this.name = name
      this.type = type
      this.age = age
    }

    Dog.prototype = {
      run() {
        console.log(this.name + "在奔跑");
      },
      showSelf() {
        console.log("我今年" + this.age + "岁啦！");
      }
    }

    var xiaohei = new Dog({
      name: "小黑",
      type: "泰迪",
      age: 3
    })

    xiaohei.showSelf()
    xiaohei.run()

    // 继承
    function Teddy({name, type, age, color}) {
      Dog.call(this, {
        name: name,
        type: type,
        age: age
      })
      this.color = color
    }

    var xiaohua = new Teddy({
      name: "小花",
      type: "拉布拉多",
      age: 1,
      color: "红色"
    })
    console.log(xiaohua.color)
  </script>
</body>

</html>